﻿using System.Text;
using JinShun.OA.UI.Apis;
using JinShun.OA.UI.Auth;
using JinShun.OA.UI.Components;
using JinShun.OA.UI.IServer.Navigation;
using JinShun.OA.UI.IServer.Post;
using JinShun.OA.UI.IServer.User;
using JinShun.OA.UI.Services.Navigation;
using JinShun.OA.UI.Services.Post;
using JinShun.OA.UI.Services.User;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.SignalR;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

builder.Services.AddRazorComponents().AddInteractiveServerComponents();

builder.Services.AddBootstrapBlazor();




builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddScoped<AuthenticationStateProvider, AntSKAuthProvider>();
builder.Services.AddScoped<HttpWebClient>();
builder.Services.AddScoped<TokenHelper>();
builder.Services.AddScoped<INavigation, NavigationService>();
builder.Services.AddScoped<IPost, PostService>();
builder.Services.AddScoped<IUser, UserService>();



// 增加 SignalR 服务数据传输大小限制配置
builder.Services.Configure<HubOptions>(option => option.MaximumReceiveMessageSize = null);

//增加API允许跨域调用
builder.Services.AddCors(options => options.AddPolicy("Any",
    builder =>
    {
        builder.AllowAnyMethod()
            .AllowAnyHeader()
            .SetIsOriginAllowed(_ => true)
            .AllowCredentials();
    }));

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseResponseCompression();
}

app.UseStaticFiles();

app.UseAntiforgery();

app.MapRazorComponents<App>().AddInteractiveServerRenderMode();

app.Run();
